#!/usr/bin/python3
# -*- coding: utf-8 -*-

"""
Py40 PyQt5 tutorial 

In this example, we connect a signal
of a QSlider to a slot of a QLCDNumber. 

author: Jan Bodnar
website: py40.com 
last edited: January 2015
"""

import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import (QWidget, QLCDNumber, QSlider, QVBoxLayout, QApplication)


class Example(QWidget):
    
    def __init__(self):
        super().__init__()
        
        self.initUI()
        
        
    def initUI(self):
        
        lcd = QLCDNumber(self)              #加入数码管字体
        sld = QSlider(Qt.Horizontal, self)  #添加一个水平滑动条
        sld.setMinimum(0)                   #设置最小值
        sld.setMaximum(100)                 #设置最大值

        vbox = QVBoxLayout()                #添加一个竖直盒子布局
        vbox.addWidget(lcd)
        vbox.addWidget(sld)

        self.setLayout(vbox)
        sld.valueChanged.connect(lcd.display) #滑块值变化时连接到lcd.display(self,value)函数
        
        self.setGeometry(300, 300, 500, 300)
        self.setWindowTitle('Signal slot')
        self.show()
        

if __name__ == '__main__':
    
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())

